﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HelpNetwork
{

    public partial class Autentificare : Form
    {
        private const String utilizatortest = "pacient";
        private const String parolatest = "test";

        private String user;
        private String parola;
        private bool fileFound = false;
        
        public Autentificare()
        {
            InitializeComponent();
        }


        private void btnAutentificare_Click(object sender, EventArgs e)
        {
            if (fileFound == false)
            {
                user = txtUtilizator.Text;
                parola = txtParola.Text;
            }
            if (cbSalvareDateAuth.Checked == true)
            {
                if (fileFound == false)
                    Parametrii.salvareDateAutentificare(ref user, ref parola);
            }
            else
            {
                Parametrii.stergereFisier();
            }
            int comparePass;
            if (fileFound == false)
                comparePass = txtParola.Text.GetHashCode();
            else
                comparePass = Int32.Parse(parola);
            if ((comparePass == parolatest.GetHashCode()) && (txtUtilizator.Text == utilizatortest))
            {
                SplashScreen.ShowSplashScreen();
                this.Hide();
                this.Close();
            }
            else
            {
             
                MessageBox.Show("Utilizator sau parola gresita!","Autentificare",MessageBoxButtons.OK,MessageBoxIcon.Error); 
            }
        }

        private void Autentificare_Load(object sender, EventArgs e)
        {   
            if (Parametrii.verificareFisier ())
            {
                Parametrii.citireDateAutentificare(ref user, ref parola);
                txtParola.Text = parola ;
                txtUtilizator.Text = user ;
                cbSalvareDateAuth.Checked = true;
                fileFound = true;
            }
        }

        private void Autentificare_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btnAutentificare.PerformClick();
        }

        private void btnCitireRFID_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Nu s-a detectat niciun cititor de RFID conectat la TinyPC.", "Lipsa cititor RFID", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        private void txtParola_TextChanged(object sender, EventArgs e)
        {
            fileFound = false;
        }
    }
}
